/*
board-games:	An educational framework for board games programming.
    Copyright (C) 2008  Daniel Gutson, FuDePAN
    
    This file is part of board-games.

    board-games is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    board-games is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
*/

#include <unistd.h>
#include <sys/wait.h>
#include "pipe.h"
#include "shobj.h"
#include "referee_side.h"

void RefereeData::load(const char* objname, PlayersProxy* playersProxy)
{
    shobj.load(objname);
    // look for initialization function:
    typedef Referee* Initialize(PlayersProxy* playersProxy);
    Initialize* initFunc = shobj.load_func<Initialize*>("initialize");
    referee = initFunc(playersProxy);
    if (referee == NULL)
        throw "Error initializing referee";
        
    if (!referee->accepts_number_of_players(playersProxy->number_of_players()))
    {
        //std::cerr<< "Invalid number of players\n";
        throw SetupException("Invalid number of players");
        //throw 1;
    }
}

int RefereeData::do_match() throw(PlayerID, const char*)
{
    return referee->do_match();
}
